{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "identified-honor",
   "metadata": {},
   "source": [
    "# Experiments Local Test\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "written-airfare",
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "from collections import defaultdict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "permanent-swimming",
   "metadata": {},
   "outputs": [],
   "source": [
    "def testJson(model, iterations):\n",
    "    cnts = defaultdict(int)\n",
    "    %env model=$model\n",
    "    for i in range(iterations):\n",
    "        res = !curl -s http://0.0.0.0:9000/v2/models/${model}/infer -H \"Content-Type: application/json\" -H \"seldon-model: ${model}\"\\\n",
    "            -d '{\"inputs\": [{\"name\": \"predict\", \"shape\": [1, 4], \"datatype\": \"FP32\", \"data\": [[1, 2, 3, 4]]}]}'\n",
    "        res = json.loads(res[0])\n",
    "        cnts[res[\"model_name\"]] += 1\n",
    "    for name,cnt in cnts.items():\n",
    "        print(name,cnt)\n",
    "\n",
    "def testGrpc(model, iterations):\n",
    "    cnts = defaultdict(int)\n",
    "    %env model=$model\n",
    "    for i in range(iterations):\n",
    "        res = !grpcurl -d '{\"model_name\":\"iris\",\"inputs\":[{\"name\":\"input\",\"contents\":{\"fp32_contents\":[1,2,3,4]},\"datatype\":\"FP32\",\"shape\":[1,4]}]}' \\\n",
    "              -plaintext \\\n",
    "              -import-path ../../apis \\\n",
    "              -proto ../../apis/mlops/v2_dataplane/v2_dataplane.proto \\\n",
    "              -rpc-header \"seldon-model: ${model}\" \\\n",
    "              0.0.0.0:9000 inference.GRPCInferenceService/ModelInfer\n",
    "        res = json.loads(''.join(res))\n",
    "        cnts[res[\"modelName\"]] += 1       \n",
    "    for name,cnt in cnts.items():\n",
    "        print(name,cnt)\n",
    "        \n",
    "def testExperimentJson(experiment, iterations):\n",
    "    cnts = defaultdict(int)\n",
    "    %env model=$experiment\n",
    "    for i in range(iterations):\n",
    "        res = !curl -s http://0.0.0.0:9000/v2/models/exp1/infer -H \"Content-Type: application/json\" -H \"seldon-model: ${model}.experiment\"\\\n",
    "            -d '{\"inputs\": [{\"name\": \"predict\", \"shape\": [1, 4], \"datatype\": \"FP32\", \"data\": [[1, 2, 3, 4]]}]}'\n",
    "        try:\n",
    "            res = json.loads(res[0])\n",
    "            cnts[res[\"model_name\"]] += 1\n",
    "        except:\n",
    "            print(\"No results returned\")\n",
    "            break\n",
    "    for name,cnt in cnts.items():\n",
    "        print(name,cnt)\n",
    "        \n",
    "def testExperimentGrpc(experiment, iterations):\n",
    "    cnts = defaultdict(int)\n",
    "    %env model=$experiment\n",
    "    for i in range(iterations):\n",
    "        res = !grpcurl -d '{\"model_name\":\"exp1\",\"inputs\":[{\"name\":\"input\",\"contents\":{\"fp32_contents\":[1,2,3,4]},\"datatype\":\"FP32\",\"shape\":[1,4]}]}' \\\n",
    "              -plaintext \\\n",
    "              -import-path ../../apis \\\n",
    "              -proto ../../apis/mlops/v2_dataplane/v2_dataplane.proto \\\n",
    "              -rpc-header \"seldon-model:${model}.experiment\" \\\n",
    "              0.0.0.0:9000 inference.GRPCInferenceService/ModelInfer\n",
    "        res = json.loads(''.join(res))\n",
    "        cnts[res[\"modelName\"]] += 1       \n",
    "    for name,cnt in cnts.items():\n",
    "        print(name,cnt)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "provincial-sewing",
   "metadata": {},
   "source": [
    "## Experiment over two iris model with default model iris"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "interstate-professional",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{ \\\n",
    "              \"meta\":{\"name\":\"iris\"},\\\n",
    "              \"modelSpec\":{\"uri\":\"gs://seldon-models/mlserver/iris\",\\\n",
    "                           \"requirements\":[\"sklearn\"],\\\n",
    "                           \"memoryBytes\":500},\\\n",
    "              \"deploymentSpec\":{\"replicas\":1}}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/LoadModel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dedicated-booth",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"name\":\"mlserver\"}' \\\n",
    "         -plaintext \\\n",
    "         -proto ../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/ServerStatus"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "automatic-yugoslavia",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{ \\\n",
    "              \"meta\":{\"name\":\"iris2\"},\\\n",
    "              \"modelSpec\":{\"uri\":\"gs://seldon-models/mlserver/iris\",\\\n",
    "                           \"requirements\":[\"sklearn\"],\\\n",
    "                           \"memoryBytes\":500},\\\n",
    "              \"deploymentSpec\":{\"replicas\":1}}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/LoadModel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "sharing-translator",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"name\":\"mlserver\"}' \\\n",
    "         -plaintext \\\n",
    "         -proto ../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/ServerStatus"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "directed-conversion",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"experiment\":{\"name\":\"exp1\", \\\n",
    "               \"defaultModel\":\"iris\", \\\n",
    "                \"candidates\":[\\\n",
    "                    {\"modelName\":\"iris\",\"weight\":50},\\\n",
    "                    {\"modelName\":\"iris2\",\"weight\":50}\\\n",
    "                    ]}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/StartExperiment"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "republican-confidence",
   "metadata": {},
   "outputs": [],
   "source": [
    "testJson(\"iris\",50)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "insured-wednesday",
   "metadata": {},
   "outputs": [],
   "source": [
    "testGrpc(\"iris\",50)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "spare-tooth",
   "metadata": {},
   "outputs": [],
   "source": [
    "testExperimentJson(\"exp1\", 50)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "permanent-wayne",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"name\":\"exp1\"}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/StopExperiment"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "paperback-ridge",
   "metadata": {},
   "outputs": [],
   "source": [
    "testJson(\"iris\", 50)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "editorial-railway",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{\"name\":\"iris\"}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/UnloadModel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "continuous-assault",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{\"name\":\"iris2\"}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/UnloadModel"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "natural-structure",
   "metadata": {},
   "source": [
    "## Experiment over two iris models"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "described-money",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{ \\\n",
    "              \"meta\":{\"name\":\"iris\"},\\\n",
    "              \"modelSpec\":{\"uri\":\"gs://seldon-models/mlserver/iris\",\\\n",
    "                           \"requirements\":[\"sklearn\"],\\\n",
    "                           \"memoryBytes\":500},\\\n",
    "              \"deploymentSpec\":{\"replicas\":1}}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/LoadModel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "outside-hypothetical",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{ \\\n",
    "              \"meta\":{\"name\":\"iris2\"},\\\n",
    "              \"modelSpec\":{\"uri\":\"gs://seldon-models/mlserver/iris\",\\\n",
    "                           \"requirements\":[\"sklearn\"],\\\n",
    "                           \"memoryBytes\":500},\\\n",
    "              \"deploymentSpec\":{\"replicas\":1}}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/LoadModel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "communist-principal",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"name\":\"mlserver\"}' \\\n",
    "         -plaintext \\\n",
    "         -proto ../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/ServerStatus"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "coordinated-venezuela",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"experiment\":{\"name\":\"exp1\", \\\n",
    "                \"candidates\":[{\"modelName\":\"iris\",\"weight\":50},{\"modelName\":\"iris2\",\"weight\":50}]}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/StartExperiment"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cross-providence",
   "metadata": {},
   "outputs": [],
   "source": [
    "testExperimentJson(\"exp1\", 50)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "opponent-helen",
   "metadata": {},
   "outputs": [],
   "source": [
    "testExperimentGrpc(\"exp1\", 50)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "racial-stanford",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"name\":\"exp1\"}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/StopExperiment"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dd083ae4",
   "metadata": {},
   "outputs": [],
   "source": [
    "testExperimentJson(\"exp1\", 50)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "judicial-threat",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{\"name\":\"iris\"}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/UnloadModel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "closed-gazette",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{\"name\":\"iris2\"}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/UnloadModel"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "educated-coordination",
   "metadata": {},
   "source": [
    "## Test Experiment created before models"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "working-lodging",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"experiment\":{\"name\":\"exp1\", \\\n",
    "               \"defaultModel\":\"iris\", \\\n",
    "                \"candidates\":[\\\n",
    "                    {\"modelName\":\"iris\",\"weight\":50},\\\n",
    "                    {\"modelName\":\"iris2\",\"weight\":50}\\\n",
    "                    ]}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/StartExperiment"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "czech-shower",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{ \\\n",
    "              \"meta\":{\"name\":\"iris\"},\\\n",
    "              \"modelSpec\":{\"uri\":\"gs://seldon-models/mlserver/iris\",\\\n",
    "                           \"requirements\":[\"sklearn\"],\\\n",
    "                           \"memoryBytes\":500},\\\n",
    "              \"deploymentSpec\":{\"replicas\":1}}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/LoadModel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "binding-browser",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{ \\\n",
    "              \"meta\":{\"name\":\"iris2\"},\\\n",
    "              \"modelSpec\":{\"uri\":\"gs://seldon-models/mlserver/iris\",\\\n",
    "                           \"requirements\":[\"sklearn\"],\\\n",
    "                           \"memoryBytes\":500},\\\n",
    "              \"deploymentSpec\":{\"replicas\":1}}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/LoadModel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "limited-advisory",
   "metadata": {},
   "outputs": [],
   "source": [
    "testJson(\"iris\", 50)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "piano-lightning",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"name\":\"exp1\"}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/StopExperiment"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "surgical-amber",
   "metadata": {},
   "outputs": [],
   "source": [
    "testGrpc(\"iris\", 50)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "temporal-yacht",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{\"name\":\"iris\"}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/UnloadModel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "atomic-polymer",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{\"name\":\"iris2\"}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/UnloadModel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "defined-lending",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"experiment\":{\"name\":\"exp1\", \\\n",
    "                \"candidates\":[{\"modelName\":\"iris\",\"weight\":50},{\"modelName\":\"iris2\",\"weight\":50}]}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/StartExperiment"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "comfortable-massage",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{ \\\n",
    "              \"meta\":{\"name\":\"iris\"},\\\n",
    "              \"modelSpec\":{\"uri\":\"gs://seldon-models/mlserver/iris\",\\\n",
    "                           \"requirements\":[\"sklearn\"],\\\n",
    "                           \"memoryBytes\":500},\\\n",
    "              \"deploymentSpec\":{\"replicas\":1}}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/LoadModel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "resident-default",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{ \\\n",
    "              \"meta\":{\"name\":\"iris2\"},\\\n",
    "              \"modelSpec\":{\"uri\":\"gs://seldon-models/mlserver/iris\",\\\n",
    "                           \"requirements\":[\"sklearn\"],\\\n",
    "                           \"memoryBytes\":500},\\\n",
    "              \"deploymentSpec\":{\"replicas\":1}}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/LoadModel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "retired-negative",
   "metadata": {},
   "outputs": [],
   "source": [
    "testJson(\"iris\", 50)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "corrected-clear",
   "metadata": {},
   "outputs": [],
   "source": [
    "testExperimentJson(\"exp1\", 50)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "posted-offering",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"name\":\"exp1\"}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/StopExperiment"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "eastern-collective",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{\"name\":\"iris\"}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/UnloadModel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fourth-highland",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{\"name\":\"iris2\"}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/UnloadModel"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "consecutive-longitude",
   "metadata": {},
   "source": [
    "## Change Experiment"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "exceptional-composite",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{ \\\n",
    "              \"meta\":{\"name\":\"iris\"},\\\n",
    "              \"modelSpec\":{\"uri\":\"gs://seldon-models/mlserver/iris\",\\\n",
    "                           \"requirements\":[\"sklearn\"],\\\n",
    "                           \"memoryBytes\":500},\\\n",
    "              \"deploymentSpec\":{\"replicas\":1}}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/LoadModel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "greater-timeline",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{ \\\n",
    "              \"meta\":{\"name\":\"iris2\"},\\\n",
    "              \"modelSpec\":{\"uri\":\"gs://seldon-models/mlserver/iris\",\\\n",
    "                           \"requirements\":[\"sklearn\"],\\\n",
    "                           \"memoryBytes\":500},\\\n",
    "              \"deploymentSpec\":{\"replicas\":1}}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/LoadModel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "manufactured-track",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{ \\\n",
    "              \"meta\":{\"name\":\"iris3\"},\\\n",
    "              \"modelSpec\":{\"uri\":\"gs://seldon-models/mlserver/iris\",\\\n",
    "                           \"requirements\":[\"sklearn\"],\\\n",
    "                           \"memoryBytes\":500},\\\n",
    "              \"deploymentSpec\":{\"replicas\":1}}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/LoadModel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "forced-conjunction",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"name\":\"mlserver\"}' \\\n",
    "         -plaintext \\\n",
    "         -proto ../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/ServerStatus"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "consolidated-consensus",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"experiment\":{\"name\":\"exp1\", \\\n",
    "               \"defaultModel\":\"iris\", \\\n",
    "                \"candidates\":[\\\n",
    "                    {\"modelName\":\"iris\",\"weight\":50},\\\n",
    "                    {\"modelName\":\"iris2\",\"weight\":50}\\\n",
    "                    ]}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/StartExperiment"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "spiritual-castle",
   "metadata": {},
   "outputs": [],
   "source": [
    "testJson(\"iris\", 50)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "level-generic",
   "metadata": {},
   "outputs": [],
   "source": [
    "testJson(\"iris2\", 50)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "nominated-lightning",
   "metadata": {},
   "outputs": [],
   "source": [
    "testExperimentJson(\"exp1\", 50)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "preliminary-rehabilitation",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"experiment\":{\"name\":\"exp1\", \\\n",
    "               \"defaultModel\":\"iris2\", \\\n",
    "                \"candidates\":[\\\n",
    "                    {\"modelName\":\"iris2\",\"weight\":50},\\\n",
    "                    {\"modelName\":\"iris3\",\"weight\":50}\\\n",
    "                    ]}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/StartExperiment"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "active-beach",
   "metadata": {},
   "outputs": [],
   "source": [
    "testJson(\"iris\", 50)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "rising-disability",
   "metadata": {},
   "outputs": [],
   "source": [
    "testJson(\"iris2\", 50)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "false-experiment",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"name\":\"exp1\"}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/StopExperiment"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "blank-guarantee",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{\"name\":\"iris\"}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/UnloadModel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "meaning-knitting",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{\"name\":\"iris2\"}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/UnloadModel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "biological-intranet",
   "metadata": {},
   "outputs": [],
   "source": [
    "!grpcurl -d '{\"model\":{\"name\":\"iris3\"}}' \\\n",
    "         -plaintext \\\n",
    "         -import-path ../../apis \\\n",
    "         -proto ../../apis/mlops/scheduler/scheduler.proto  0.0.0.0:9004 seldon.mlops.scheduler.Scheduler/UnloadModel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "brief-mandate",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
